<?php 
$v_customer_record_id = 0;
if(isset($_REQUEST['hdn_customer_record_id'])){
	$v_customer_record_id = intval($_REQUEST['hdn_customer_record_id']);
}
$v_status_of_receiving = 0;
$v_approving_type = "";
if(isset($_REQUEST['hdn_approving_type'])){
	$v_approving_type = $_REQUEST['hdn_approving_type'];
}
//Ngay hen nop ho so goc
$v_receiving_date = "";
if(isset($_REQUEST['txt_receiving_date'])){
	$v_receiving_date = _ddmmyyyy_to_yyyymmdd($_REQUEST['txt_receiving_date']);
}
//Ngay tiep nhan ho so goc
$v_official_receiving_date = "";
if(isset($_REQUEST['txt_official_receiving_date'])){
	$v_official_receiving_date = _ddmmyyyy_to_yyyymmdd($_REQUEST['txt_official_receiving_date']);
}
//Ngay tiep nhan ho so goc
$v_official_appointed_date = "";
if(isset($_REQUEST['txt_official_appointed_date'])){
	$v_official_appointed_date = _ddmmyyyy_to_yyyymmdd($_REQUEST['txt_official_appointed_date']);
}
switch($v_approving_type) {	
	case "APPROVING";
		$v_status_of_receiving = 1;
		break;
	case "NOT_APPROVING";
		$v_status_of_receiving = 0;
		break;
	case "OFFICIAL";
		$v_status_of_receiving = 9;
		break;
	case "NOT_OFFICIAL";
		$v_status_of_receiving = 1;
		break;
}
$v_text_id = 0;
$v_message_text = "";
if(isset($_REQUEST['txt_warning_content'])){
	$v_message_text = trim(_replace_bad_char(trim($_REQUEST['txt_warning_content'])));
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Cap nhat moi ho so
$v_record_id = 0 ;
$v_status = $arr_record_status[0][0];
$v_recordtype = $_REQUEST['hdn_recordtype_filter'];
$v_receiver_id = $_SESSION['staff_id'];
$v_code_record = "";
if(isset($_REQUEST['hdn_code'])){
	$v_code_record = _replace_bad_char($_REQUEST['hdn_code']);
}
//Begin//Xay dung chuoi XML chua gi tri cua 
$v_list_xml_tag = "";
if(isset($_REQUEST['hdn_list_xml_tag'])){
	$v_list_xml_tag = $_REQUEST['hdn_list_xml_tag'];
}
$v_list_xml_value = "";
if(isset($_REQUEST['hdn_list_xml_value'])){
	$v_list_xml_value = $_REQUEST['hdn_list_xml_value'];
}
$strXML = '<?xml version="1.0" encoding="UTF-8"?><root><data_list>';
for ($i=0;$i<_list_get_len($v_list_xml_tag,_CONST_SUB_LIST_DELIMITOR);$i++){
	$strXML = $strXML ."<"._list_get_at($v_list_xml_tag,$i,_CONST_SUB_LIST_DELIMITOR).">";
	$strXML = $strXML .trim(_replace_XML_bad_char(_list_get_at($v_list_xml_value,$i,_CONST_SUB_LIST_DELIMITOR)));
	$strXML = $strXML ."</"._list_get_at($v_list_xml_tag,$i,_CONST_SUB_LIST_DELIMITOR).">";
}
$strXML = $strXML . "</data_list></root>";
//End//Lay danh sach cac the XML va gia tri tuong ung voi tung the do
$v_worktype = "TIEP_NHAN";
//echo '<br>'.'v_approving_type'.$v_approving_type.'<br><br>'; //exit;
//Trang thai thieu HS hay khong? 0: Ung voi thieu HS; 1: Ung voi du HS
$v_status_minus_record = 1;
$v_new_file_id_list = "";
$v_deleted_exist_file_id_list = "";
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if(_is_sqlserver()){
	$v_text_id = _save_text_to_database('T_TEMP_FILE', 'C_TEXT', $v_message_text);
	$received_record_xml_date_id = _save_XML_to_database('T_TEMP_FILE', 'PK_TEMP_FILE', 'C_TEXT', $strXML);
	$sql = "Exec Onegate_CustomerRecordUpdateForApproving " ;
	$sql = $sql . " " .  $v_customer_record_id ;
	$sql = $sql . ",'" . $v_receiving_date . "'" ;		
	$sql = $sql . "," . $v_status_of_receiving ;
	$sql = $sql . "," . $v_text_id;
	//echo $sql; exit;
	$ado_conn->SetFetchMode(ADODB_FETCH_ASSOC);
	$rs = $ado_conn->GetRow($sql); 
	$v_error = _replace_bad_char(trim($rs['RET_ERROR']));
	if($v_customer_record_id <= 0){
		$v_customer_record_id = $rs['NEW_ID'];
	}
	if($v_approving_type == "OFFICIAL") {	
		$sql = "Exec Onegate_RecordUpdate " ;
		$sql = $sql . " " .  $v_record_id ;
		$sql = $sql . ",'" . $v_status . "'"  ;
		$sql = $sql . ",'" . $v_recordtype . "'"  ;
		$sql = $sql . "," .  $v_receiver_id ;
		$sql = $sql . ",'" . $v_code_record . "'" ;
		$sql = $sql . ",'" . $v_official_receiving_date . "'" ;
		$sql = $sql . ",'" . $v_official_appointed_date . "'" ;
		$sql = $sql . "," .  $received_record_xml_date_id ;
		$sql = $sql . ",'" . $v_worktype . "'" ;
		$sql = $sql . "," . $_ISA_AUTOMATIC_UPDATE_WORK_LIST;
		$sql = $sql . "," . $v_status_minus_record;	
		$sql = $sql . ",'" . $v_new_file_id_list . "'" ;
		$sql = $sql . ",'" . $v_deleted_exist_file_id_list . "'" ;
		//echo $sql; exit;
		$ado_conn->SetFetchMode(ADODB_FETCH_ASSOC);
		$rs = $ado_conn->GetRow($sql);
		$v_error = _replace_bad_char(trim($rs['RET_ERROR']));
		$v_record_id = $rs['NEW_ID'];
	}
}
sleep(0);
if (!is_null($v_error) && $v_error<>""){?>
	<script>
		alert("<?php echo $v_error; ?>");
		if (_MODAL_DIALOG_MODE==1){
			window.location = "<?php echo $v_goto_url; ?>";
		}else{
			window.history.back();
		}	
	</script><?php
	exit;
}
switch($v_check_worktype) {	
	case "APPROVING";
		$v_fuseaction = "DISPLAY_ALL_NET_RECORD_FOR_APPROVING";
		break;
	case "OFFICIAL_RECEIVE";
		$v_fuseaction = "DISPLAY_ALL_NET_RECORD_OFFICIAL_RECEIVE";
		break;
}
?>
<form action="index.php" method="post" name="f_back">
	<input type="hidden" name="fuseaction" value="<?php echo $v_fuseaction;?>">
	<input type="hidden" name="hdn_record_id" value="<?php echo $v_record_id;?>">
</form>
<Script language="javascript">
	document.forms(0).submit();
</Script>